home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / sound / audiocodec / ulawcodec.r < prev    next >
Encoding:
Text File  |  2000-09-28  |  7.9 KB  |  217 lines

  1. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. // defines needed before including headers
  3.  
  4. // use the platform info array in the 'thng' resource for 68k and PowerPC, or Windows
  5. #define thng_RezTemplateVersion 1
  6.  
  7. #define DLOG_RezTemplateVersion 1
  8.  
  9.  
  10. #include "MacTypes.r"
  11. #include "Components.r"
  12. #include "Sound.r"
  13. #include "Icons.r"
  14. #include "Dialogs.r"
  15. #include "Appearance.r"
  16.  
  17. #include "uLawCodec.h"
  18.  
  19. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  20. // µLaw decompressor
  21.  
  22. resource 'thng' (kSoundDecompressorResID, ULawDecompressorName, purgeable) {
  23.     kSoundDecompressor, kCodecFormat, kSoundComponentManufacturer, 
  24.     k16BitIn|kStereoIn | k8BitRawOut|k16BitOut|kStereoOut, 0,
  25.     kSoundComponentType, kSoundDecompressorResID,
  26.     'STR ', kSoundCodecNameStringResID,
  27.     'STR ', kSoundCodecInfoStringResID,
  28.     'ICON', kSoundComponentIconResID,
  29.     kSoundDecompressorVersion,
  30.     componentDoAutoVersion|componentHasMultiplePlatforms, 0,
  31.     {
  32. #if TARGET_OS_MAC
  33.         k16BitIn|kStereoIn | k8BitRawOut|k16BitOut|kStereoOut,
  34.             kSoundComponentType, kSoundDecompressorResID, platform68k;
  35.         k16BitIn|kStereoIn | k8BitRawOut|k16BitOut|kStereoOut,
  36.             kSoundComponentPPCType, kSoundDecompressorResID, platformPowerPC
  37. #else
  38.         k16BitIn|kStereoIn | k8BitRawOut|k16BitOut|kStereoOut,
  39.             'dlle', kSoundDecompressorResID, platformWin32
  40. #endif
  41.     }
  42. };
  43.  
  44.  
  45. // name and info string are shared by the compressor and decompressor
  46. resource 'STR ' (kSoundCodecNameStringResID, ULawDecompressorName, purgeable) {
  47.     "Example µLaw 2:1"
  48. };
  49.  
  50. resource 'STR ' (kSoundCodecInfoStringResID, ULawDecompressorName, purgeable) {
  51.     "µLaw (CCITT Recommendation G.711) compression with a 2 to 1 ratio."
  52. };
  53.  
  54. resource 'ICON' (kSoundComponentIconResID, ULawDecompressorName, purgeable) {
  55.     $"00000000000000000000000000000000"
  56.     $"00000000003FC00001C0380002040400"
  57.     $"022A840003915F80027FE44002000720"
  58.     $"020004A0020004A0020004A0020004A0"
  59.     $"020004A0020007200200044002000780"
  60.     $"0200040001C03800003FC00000001000"
  61.     $"00888000002020000085400000100000"
  62.     $"0042"
  63. };
  64.  
  65. #if !TARGET_OS_MAC
  66. resource 'dlle' (kSoundDecompressorResID, ULawDecompressorName) {
  67.     "__uLawDecompComponentDispatch"
  68. };
  69. #endif
  70.  
  71.  
  72. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. // µLaw compressor
  74.  
  75. resource 'thng' (kSoundCompressorResID, ULawCompressorName, purgeable) {
  76.     kSoundCompressor, kCodecFormat, kSoundComponentManufacturer,
  77.     k16BitIn|kStereoIn | k8BitRawOut|k16BitOut|kStereoOut, 0,
  78.     kSoundComponentType, kSoundCompressorResID,
  79.     'STR ', kSoundCodecNameStringResID,
  80.     'STR ', kSoundCodecInfoStringResID,
  81.     'ICON', kSoundComponentIconResID,
  82.     kSoundCompressorVersion,
  83.     componentDoAutoVersion|componentHasMultiplePlatforms, 0,
  84.     {
  85. #if TARGET_OS_MAC
  86.         k16BitIn|kStereoIn | k8BitRawOut|k16BitOut|kStereoOut,
  87.             kSoundComponentType, kSoundCompressorResID, platform68k;
  88.         k16BitIn|kStereoIn | k8BitRawOut|k16BitOut|kStereoOut,
  89.             kSoundComponentPPCType, kSoundCompressorResID, platformPowerPC
  90. #else
  91.         k16BitIn|kStereoIn | k8BitRawOut|k16BitOut|kStereoOut,
  92.             'dlle', kSoundCompressorResID, platformWin32
  93. #endif
  94.     }
  95. };
  96.  
  97.  
  98. #if !TARGET_OS_MAC
  99. resource 'dlle' (kSoundCompressorResID, ULawCompressorName) {
  100.     "__uLawCompComponentDispatch"
  101. };
  102. #endif
  103.  
  104.  
  105. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  106. // µLaw decompressor table
  107.  
  108. type k16BitTableResType {
  109.     array {
  110.         integer;            // array of 16 bit integers
  111.     };
  112. };
  113.  
  114. // make the resource locked since it's always locked while in use,
  115. // marking it locked helps memory management: Resource Mgr will load it lower in heap
  116.  
  117. resource k16BitTableResType (kSoundDecompressorResID, ULawDecompressorName, locked) {
  118.     {
  119.         -32124, -31100, -30076, -29052, -28028, -27004, -25980, -24956,
  120.         -23932, -22908, -21884, -20860, -19836, -18812, -17788, -16764,
  121.         -15996, -15484, -14972, -14460, -13948, -13436, -12924, -12412,
  122.         -11900, -11388, -10876, -10364,  -9852,  -9340,  -8828,  -8316,
  123.         -7932,  -7676,  -7420,  -7164,  -6908,  -6652,  -6396,  -6140,
  124.         -5884,  -5628,  -5372,  -5116,  -4860,  -4604,  -4348,  -4092,
  125.         -3900,  -3772,  -3644,  -3516,  -3388,  -3260,  -3132,  -3004,
  126.         -2876,  -2748,  -2620,  -2492,  -2364,  -2236,  -2108,  -1980,
  127.         -1884,  -1820,  -1756,  -1692,  -1628,  -1564,  -1500,  -1436,
  128.         -1372,  -1308,  -1244,  -1180,  -1116,  -1052,   -988,   -924,
  129.         -876,   -844,   -812,   -780,   -748,   -716,   -684,   -652,
  130.         -620,   -588,   -556,   -524,   -492,   -460,   -428,   -396,
  131.         -372,   -356,   -340,   -324,   -308,   -292,   -276,   -260,
  132.         -244,   -228,   -212,   -196,   -180,   -164,   -148,   -132,
  133.         -120,   -112,   -104,    -96,    -88,    -80,    -72,    -64,
  134.         -56,    -48,    -40,    -32,    -24,    -16,     -8,      0,
  135.         32124,  31100,  30076,  29052,  28028,  27004,  25980,  24956,
  136.         23932,  22908,  21884,  20860,  19836,  18812,  17788,  16764,
  137.         15996,  15484,  14972,  14460,  13948,  13436,  12924,  12412,
  138.         11900,  11388,  10876,  10364,   9852,   9340,   8828,   8316,
  139.         7932,   7676,   7420,   7164,   6908,   6652,   6396,   6140,
  140.         5884,   5628,   5372,   5116,   4860,   4604,   4348,   4092,
  141.         3900,   3772,   3644,   3516,   3388,   3260,   3132,   3004,
  142.         2876,   2748,   2620,   2492,   2364,   2236,   2108,   1980,
  143.         1884,   1820,   1756,   1692,   1628,   1564,   1500,   1436,
  144.         1372,   1308,   1244,   1180,   1116,   1052,    988,    924,
  145.         876,    844,    812,    780,    748,    716,    684,    652,
  146.         620,    588,    556,    524,    492,    460,    428,    396,
  147.         372,    356,    340,    324,    308,    292,    276,    260,
  148.         244,    228,    212,    196,    180,    164,    148,    132,
  149.         120,    112,    104,     96,     88,     80,     72,     64,
  150.          56,     48,     40,     32,     24,     16,      8,      0,
  151.     }
  152. };
  153.  
  154. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  155. // µLaw compressor exponent table
  156.  
  157. type k8BitTableResType {
  158.     array {
  159.         byte;                // array of bytes
  160.     };
  161. };
  162.  
  163. // make the resource locked since it's always locked while in use,
  164. // marking it locked helps memory management: Resource Mgr will load it lower in heap
  165.  
  166. resource k8BitTableResType (kSoundCompressorResID, ULawCompressorName, locked) {
  167.     {
  168.         0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 
  169.         4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
  170.         5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 
  171.         5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 
  172.         6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 
  173.         6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 
  174.         6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 
  175.         6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 
  176.         7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 
  177.         7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 
  178.         7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 
  179.         7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 
  180.         7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 
  181.         7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 
  182.         7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 
  183.         7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 
  184.     }
  185. };
  186.  
  187. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  188. // options dialog resources
  189.  
  190. resource 'DLOG' (kSoundCompressorResID, ULawCompressorName, purgeable) {
  191.     {0, 0, 150+13, 214+13},
  192. #if TARGET_OS_MAC
  193.     dBoxProc,
  194. #else
  195.     movableDBoxProc,
  196. #endif
  197.     invisible, noGoAway, 0, kSoundCompressorResID, ULawCompressorName, alertPositionParentWindow
  198. };
  199.  
  200. resource 'DITL' (kSoundCompressorResID, ULawCompressorName, purgeable) {
  201.     {    
  202. /* [1] */    {130, 156, 150, 214}, Button {enabled, "OK"},
  203. /* [2] */    {130, 78, 150, 136}, Button {enabled, "Cancel"},
  204. /* [3] */    {13, 13, 45, 45}, Icon {disabled, kSoundComponentIconResID},
  205. /* [4] */    {26, 65, 44, 216}, CheckBox {enabled, "I like this Icon"},
  206. /* [5] */    {52, 13, 114, 217}, StaticText {disabled, "Example Sound Codec\n© 1998 Apple Computer Inc."
  207.         }
  208.     }
  209. };
  210.  
  211. resource 'dlgx' (kSoundCompressorResID, ULawCompressorName, purgeable) {
  212.     versionZero        /* sometimes the headers have this as latestVersion */
  213.     {kDialogFlagsUseThemeBackground | kDialogFlagsUseControlHierarchy | kDialogFlagsUseThemeControls}
  214. };
  215.  
  216.  
  217.